import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:kmxy_base/base/base_page_state.dart';
import 'package:kmxy_base/network/net.dart';
import 'package:kmxy_base/page/setting/net_log/net_log_page_view.dart';
import 'package:kmxy_base/util/amap_location_util.dart';
import 'package:kmxy_base/util/file_util.dart';
import 'package:kmxy_base/util/sp_util.dart';
import 'package:kmxy_base/util/string_util.dart';

abstract class NetLogPageState extends BasePageState<NetLogPage> {
  String log = '';
  ScrollController scrollController = ScrollController();

  clean() {
    Net.logText = '';
    log = Net.logText;
    setState(() {});
  }

  refresh() {
    log = Net.logText;
    setState(() {});
  }

  @override
  destroyData() {
    Net.isShowNetLogPage = false;
  }

  @override
  initData() {
    setState(() {
      log = Net.logText;
    });
    SchedulerBinding.instance.addPostFrameCallback((_) {
      scrollController.jumpTo(scrollController.position.maxScrollExtent);
    });
  }

  xjPath() async {
    String? latLngListS =
        await SpUtil.getString(AMapLocationUtil.getInstance.SP_LATLNG_LIST);
    if (latLngListS == null || latLngListS.isEmpty) {
      '没有巡检数据'.toast();
      return;
    }
    await FileUtil.saveFileDownload(latLngListS, '巡检数据.txt');
    '巡检数据保存成功'.toast();
  }
}
